home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 05.zip / BS1 part 5 / SASC_6.0_Disk_7.adf / Source_And_Examples / source / _cxbrk.c next >
Encoding:
C/C++ Source or Header  |  1992-07-30  |  3.5 KB  |  127 lines

  1. /***
  2. *
  3. *          Copyright © 1992  SAS Institute, Inc.
  4. *
  5. * name             _CXBRK  -  default signal handler for SIGINT
  6. *
  7. * synopsis         _CXBRK(sig)
  8. *                  sig             signal which caused the abort request
  9. *
  10. *
  11. * description      _CXBRK is the default signal handler used to handle
  12. *                  the SIGINT signal.  It puts up a requester asking
  13. *                  the user if he really wants to abort program execution.
  14. *                  If yes, this routine aborts the program, otherwise the
  15. *                  routine returns to normal program execution.
  16. *
  17. ***/
  18.  
  19. #include <string.h>
  20. #include <signal.h>
  21. #include <stdlib.h>
  22. #include <exec/types.h>
  23. #include <intuition/intuition.h>
  24. #include <libraries/dosextens.h>
  25. #include <proto/exec.h>
  26. #include <proto/dos.h>
  27. #include <proto/intuition.h>
  28.  
  29.  
  30. void _CXBRK(int);
  31.  
  32. static struct IntuiText Text2 = {
  33.            -1, -1,                           /* pen numbers */
  34.            0,                                /* draw mode */
  35.            14, 14,                           /* starting offsets */
  36.            NULL,                             /* text attribute pointer */
  37.            "** User Abort Requested **",
  38.            NULL
  39. };
  40.  
  41. static struct IntuiText BodyText = {
  42.            -1, -1,                           /* pen numbers */
  43.            0,                                /* draw mode */
  44.            4, 4,                             /* starting offsets */
  45.            NULL,                             /* text attribute pointer */
  46.            NULL,
  47.            &Text2
  48. };
  49.  
  50. static struct IntuiText ContinueText = {
  51.            -1, -1,                           /* pen numbers */
  52.            0,                                /* draw mode */
  53.            4, 4,                             /* starting offsets */
  54.            NULL,                             /* text attribute pointer */
  55.            "CONTINUE",
  56.            NULL
  57. };
  58.  
  59. static struct IntuiText AbortText = {
  60.            -1, -1,                           /* pen numbers */
  61.            0,                                /* draw mode */
  62.            4, 4,                             /* starting offsets */
  63.            NULL,                             /* text attribute pointer */
  64.            "ABORT",
  65.            NULL
  66. };
  67.  
  68. extern char *_ProgramName;
  69.  
  70.  
  71. void _CXBRK(sig)
  72.     int  sig;
  73. {
  74.     char   temp[81];
  75.     int    len;
  76.     struct Process *us;
  77.     BPTR   fh;
  78.     struct CommandLineInterface  *cli;
  79.     struct IntuitionBase         *IntuitionBase;
  80.  
  81.  
  82.     /*   Build the program name into temp   */
  83.  
  84.     len = _ProgramName[-1];
  85.     if (len > 79)
  86.         len = 79;
  87.     memcpy(temp, _ProgramName, len);
  88.     temp[len] = '\0';
  89.  
  90.  
  91.     /* Now see if we were invoked from CLI or from WorkBench */
  92.  
  93.     us = (struct Process *) FindTask(0L);
  94.     if (us->pr_CLI != NULL) {
  95.         cli = (struct CommandLineInterface *) (((long) (us->pr_CLI)) << 2);
  96.         fh = cli->cli_StandardOutput;
  97.         if (fh == NULL)
  98.             fh = us->pr_COS;
  99.         if (fh != NULL) {
  100.             Write(fh, "*** Break: ", 11L);
  101.             temp[len++] = '\n';
  102.             Write(fh, temp, (long) len);
  103.             __sigfunc[SIGINT] = SIG_IGN;
  104.             __exit(20);
  105.     }
  106.     }
  107.  
  108.     IntuitionBase = (struct IntuitionBase *)
  109.                            OpenLibrary("intuition.library",0);
  110.     if (IntuitionBase == NULL) {
  111.         __sigfunc[SIGINT] = SIG_IGN;
  112.         __exit(20);
  113.     }
  114.  
  115.     BodyText.IText = temp;
  116.  
  117.     if (AutoRequest(NULL, &BodyText, &ContinueText, &AbortText,
  118.                                   0L, 0L, 250L, 60L) != TRUE) {
  119.         __sigfunc[SIGINT] = SIG_IGN;
  120.         __exit(20);
  121.     }
  122.  
  123.     __sigfunc[sig] = _CXBRK;
  124.  
  125.     return;
  126. }
  127.